//
//  MBSpaceGradeRuleCell.m
//  MiBaoTu
//
//  Created by admin on 16/9/21.
//  Copyright © 2016年 com.caesartech15. All rights reserved.
//

#import "MBSpaceGradeRuleCell.h"

@implementation MBSpaceGradeRuleCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setRuleArr:(NSArray *)ruleArr
{
    _ruleArr = ruleArr;
    [self setNeedsDisplay];
}

- (void)setOrientation:(UIDeviceOrientation)orientation
{
    _orientation = orientation;
    [self setNeedsDisplay];
}

- (void)drawRect:(CGRect)rect
{
    [super drawRect:rect];
    
    //线框
    float itemWidth = 330*PERCEN;
    float itemHeight = 60*PERCEN;
    float item_x = (SCREEN_WIDTH-itemWidth*2)/2.;//40*PERCEN;
    itemWidth = (SCREEN_WIDTH-item_x*2)/3.;
    float item_y = 20*PERCEN;
    if (ISIPAD) {
        itemWidth = 532*PERCEN*(_orientation==UIDeviceOrientationPortrait?1.0*SCREEN_WIDTH/SCREEN_HEIGHT:1.);
        itemHeight = 80*PERCEN;
        item_y = 30*PERCEN;
        item_x = (SCREEN_WIDTH-itemWidth*3)/2.;
    }
    
    CGContextRef contentRef = UIGraphicsGetCurrentContext();
    CGContextMoveToPoint(contentRef, item_x, item_y);
    CGContextAddLineToPoint(contentRef, item_x, 9*itemHeight+item_y);
    CGContextAddLineToPoint(contentRef, 3*itemWidth+item_x, 9*itemHeight+item_y);
    CGContextAddLineToPoint(contentRef, 3*itemWidth+item_x, item_y);
    CGContextAddLineToPoint(contentRef, item_x, item_y);
    CGContextMoveToPoint(contentRef, itemWidth+item_x, item_y);
    CGContextAddLineToPoint(contentRef, itemWidth+item_x, 9*itemHeight+item_y);
    CGContextMoveToPoint(contentRef, itemWidth*2+item_x, item_y);
    CGContextAddLineToPoint(contentRef, itemWidth*2+item_x, 9*itemHeight+item_y);
    CGContextSetLineWidth(contentRef, 1);
    CGContextSetStrokeColorWithColor(contentRef, [UIColorFromHex(0x999999) colorWithAlphaComponent:.35].CGColor);
    for (int i=0; i<self.ruleArr.count; i++) {
        CGContextMoveToPoint(contentRef, item_x, item_y+itemHeight*(i+1));
        CGContextAddLineToPoint(contentRef, item_x+itemWidth*3, item_y+itemHeight*(i+1));
    }
    CGContextStrokePath(contentRef);
    
    for (int i=0; i<self.ruleArr.count; i++) {
        NSArray *data = [self.ruleArr objectAtIndex:i];
        NSString *str1 = data[0];
        NSString *str2 = data[2];
        NSString *str3 = data[1];
        NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc]init];;
        [style setAlignment:NSTextAlignmentCenter];
        
        [str1 drawInRect:CGRectMake(item_x, item_y+(itemHeight-16)/2.+itemHeight*i, itemWidth, itemHeight) withAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:13.f],NSForegroundColorAttributeName:UIColorFromHex(0x333333),NSParagraphStyleAttributeName:style}];
        [str3 drawInRect:CGRectMake(itemWidth+item_x, item_y+(itemHeight-16)/2.+itemHeight*i, itemWidth, itemHeight) withAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:13.f],NSForegroundColorAttributeName:UIColorFromHex(0x333333),NSParagraphStyleAttributeName:style}];
        [str2 drawInRect:CGRectMake(itemWidth*2+item_x, item_y+(itemHeight-16)/2.+itemHeight*i, itemWidth, itemHeight) withAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:13.f],NSForegroundColorAttributeName:UIColorFromHex(0x333333),NSParagraphStyleAttributeName:style}];
        
    }
    CGContextStrokePath(contentRef);
    CGContextClosePath(contentRef);
}

@end
